package com.mingqijia.gassafety.authority.security.oauth;

import com.mingqijia.gassafety.authority.security.user.SecurityUserLoginHolder;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;

/**
 * 管理员用户详情获取
 * @author Damon S.
 * @version v1.0.1
 * @date 2020年07月25日 12:16
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class ManagerDetailsServiceImpl implements UserDetailsService {

    private final SecurityUserLoginHolder holder;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        if (ObjectUtils.isEmpty(username)) {
            throw new UsernameNotFoundException("用户不存在");
        }
        return holder.findManagerFromDb(username);
    }
}
